/*
 * Copyright (C) 2010 Fred Barrie This program is free software: you can
 * redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version. This program is distributed
 * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details. You should have received
 * a copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */
package org.aergia.vinny.database.pojo;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import org.w3c.dom.Element;

/**
 * @author fred
 */
@Entity
public class VinnyRole implements DatabasePojo {

	public static final String MODIFY_CONFIGURATION = "ModifyConfiguration";

	public static final String MODIFY_SERVICE = "ModifyService";

	public static final String MODIFY_USER = "ModifyUser";

	public static final String MODIFY_VOLUNTEER = "ModifyVolunteer";

	private boolean active;
	private int id;
	private String permission;

	public VinnyRole() {
		// empty
	}

	/**
	 * @param permission
	 */
	public VinnyRole(final String permission) {
		this.permission = permission;
		this.active = true;
	}

	@Override
	public void attachAttributes(final Element element) {
		element.setAttribute("id", Integer.toString(this.getId()));
		element.setAttribute("active", Boolean.toString(this.isActive()));
		element.setAttribute("permission", this.getPermission());
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof VinnyRole)) {
			return false;
		}
		final VinnyRole other = (VinnyRole) obj;
		if (this.getPermission() == null) {
			if (other.getPermission() != null) {
				return false;
			}
		} else if (!this.getPermission().equals(other.getPermission())) {
			return false;
		}
		return true;
	}

	@Override
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return this.id;
	}

	/**
	 * @return the permission
	 */
	public String getPermission() {
		return this.permission;
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (this.getPermission() == null ? 0 : this.getPermission().hashCode());
		return result;
	}

	@Override
	public boolean isActive() {
		return this.active;
	}

	/**
	 * @param active
	 *            the active to set
	 */
	public void setActive(final boolean active) {
		this.active = active;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(final int id) {
		this.id = id;
	}

	/**
	 * @param permission
	 *            the permission to set
	 */
	public void setPermission(final String permission) {
		this.permission = permission;
	}
}
